<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\api\controller;

/**
 * Description of Login
 *
 * @author DevPHP
 * @version 2018-4-8
 */
class Login {

    public function get_login_conf() {
        $return = ['status' => 1, 'info' => '',];
        return $return;
    }

    /**
     * 功能：
     * 检测IP黑名单、帐号黑名单
     * 检测登录次数
     * 检测
     * @version 2018-4-9
     */
    public function do_login() {
        $loginType = \think\facade\Request::param('login_type');
        $ip = \think\facade\Request::ip();
        $loginModel = new \app\common\model\LoginModel();
        $result = fmt_result(false, '登录方式无效');
        switch ($loginType) {
            case 'sms':
                $user_name = request('mobile');
                $smscode = request('smscode');
                $result = $loginModel->loginWithSmscode($user_name, $smscode, $ip);
                break;
            case 'pwd':
                $user_name = request('user_name');
                $password = request('password');
                $result = $loginModel->loginWithPassword($user_name, $password, $ip);
                break;
            case 'sms_or_pwd':
                // 默认帐号密码登录
                $user_name = request('user_name');
                $password = request('password');
                $smscode = request('smscode');
                $result = $loginModel->loginWithPasswordOrSmscode($user_name, $password, $smscode, $ip);
                break;
        }
        return json_encode($result);
    }

}
